import React, { Component, lazy, Suspense  } from 'react'
import { NavLink, Route, Switch, Redirect } from 'react-router-dom'
import Loading from './components/Loadding'
// 懒加载路由引入方式
const Home = lazy(() => import('./components/Home'))
const About = lazy(() => import('./components/About'))
export default class App extends Component {
  render() {
    return (
      <div>
        <NavLink to="/home" >HOME</NavLink>
        <NavLink to="/about">ABOUT</NavLink>
        <div>
          <Suspense fallback={<Loading />}>
            <Switch>
              <Route path="/home" component={Home}></Route>
              <Route path="/about" component={About}></Route>
              <Redirect to="/" component = {Home}></Redirect>
            </Switch>
        </Suspense>
        </div>
      </div>
    )
  }
}
